Test0529;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class EmployeeManagement {
    private Map<String, String> employeeMap;

    public EmployeeManagement() {
        employeeMap = new HashMap<>();
    }

    // 添加员工信息
    public void addEmployee(String id, String name) {
        employeeMap.put(id, name);
        System.out.println("员工 " + name + "（编号：" + id + "）添加成功。");
    }

    // 查询员工信息
    public void queryEmployee(String id) {
        String name = employeeMap.get(id);
        if (name != null) {
            System.out.println("员工编号：" + id + "，员工姓名：" + name);
        } else {
            System.out.println("未找到编号为 " + id + " 的员工信息。");
        }
    }

    // 删除员工信息
    public void deleteEmployee(String id) {
        String removedName = employeeMap.remove(id);
        if (removedName != null) {
            System.out.println("员工 " + removedName + "（编号：" + id + "）删除成功。");
        } else {
            System.out.println("未找到编号为 " + id + " 的员工信息，无法删除。");
        }
    }

    // 修改员工信息
    public void updateEmployee(String id, String newName) {
        if (employeeMap.containsKey(id)) {
            employeeMap.put(id, newName);
            System.out.println("员工编号：" + id + " 的信息已更新为 " + newName);
        } else {
            System.out.println("未找到编号为 " + id + " 的员工信息，无法更新。");
        }
    }

    // 删除所有员工信息
    public void deleteAllEmployees() {
        employeeMap.clear();
        System.out.println("所有员工信息已删除。");
    }

    public static void main(String[] args) {
        EmployeeManagement management = new EmployeeManagement();
        Scanner scanner = new Scanner(System.in);
        boolean exit = false;

        while (!exit) {
            System.out.println("请选择操作：");
            System.out.println("1. 添加员工信息");
            System.out.println("2. 查询员工信息");
            System.out.println("3. 删除员工信息");
            System.out.println("4. 修改员工信息");
            System.out.println("5. 删除所有员工信息");
            System.out.println("6. 退出");

            int choice = scanner.nextInt();
            scanner.nextLine(); // 清除换行符

            switch (choice) {
                case 1:
                    System.out.print("请输入员工编号：");
                    String id = scanner.nextLine();
                    System.out.print("请输入员工姓名：");
                    String name = scanner.nextLine();
                    management.addEmployee(id, name);
                    break;
                case 2:
                    System.out.print("请输入员工编号：");
                    id = scanner.nextLine();
                    management.queryEmployee(id);
                    break;
                case 3:
                    System.out.print("请输入员工编号：");
                    id = scanner.nextLine();
                    management.deleteEmployee(id);
                    break;
                case 4:
                    System.out.print("请输入员工编号：");
                    id = scanner.nextLine();
                    System.out.print("请输入新的员工姓名：");
                    name = scanner.nextLine();
                    management.updateEmployee(id, name);
                    break;
                case 5:
                    management.deleteAllEmployees();
                    break;
                case 6:
                    exit = true;
                    System.out.println("程序退出。");
                    break;
                default:
                    System.out.println("无效的选择，请重新输入。");
            }
        }
        scanner.close();
    }
}